package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.enums.ActivityPropsConfTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ActivityPropsConf;
import com.sc.nft.mapper.ActivityPropsConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 活动道具卡配置表(sc_activity_props_conf)数据DAO
 *
 * @author Tangzehui
 * @since 2024-01-03 16:13:13
 * @description 
 */
@Slf4j
@Repository
public class ActivityPropsConfDao extends ServiceImpl<ActivityPropsConfMapper, ActivityPropsConf> {

    public void deleteByActivityPropsId(Long activityPropsId) {
        LambdaUpdateWrapper<ActivityPropsConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ActivityPropsConf::getActivityPropsId,activityPropsId);
        wrapper.set(ActivityPropsConf::getIsDelete, Boolean.TRUE);
        update(wrapper);
    }

    public List<ActivityPropsConf> getByPropsIdList(List<Long> activityPropsIdList) {
        LambdaQueryWrapper<ActivityPropsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(ActivityPropsConf::getActivityPropsId,activityPropsIdList);
        return baseMapper.selectList(wrapper);
    }

    public List<ActivityPropsConf> getExchangeByPropsId(Long activityPropsId) {
        LambdaQueryWrapper<ActivityPropsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityPropsConf::getActivityPropsId,activityPropsId);
        wrapper.eq(ActivityPropsConf::getType, ActivityPropsConfTypeEnum.EXCHANGE);
        return baseMapper.selectList(wrapper);
    }

    public ActivityPropsConf getJoinObjectByPropsId(Long activityPropsId) {
        LambdaQueryWrapper<ActivityPropsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityPropsConf::getActivityPropsId,activityPropsId);
        wrapper.eq(ActivityPropsConf::getType, ActivityPropsConfTypeEnum.OBJECT_OF_PARTICIPATION);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
}